class Solution {
    public int searchInsert(int[] nums, int target) {
        int left=0;
        int right=nums.length-1;
        while(left<right){
            int mid=left+(right-left)/2;//防止溢出
            if(nums[mid]<target){
                left=mid+1;
            }else if(nums[mid]>target){
                right=mid-1;
            }else {
                return  mid;
            }
        }
        return left;
    }
    public int addDigits(int num) {
        if(num==0){
            return 0;
        }
        int ret=0;
       while(num>0){
           int a=num%10;
            ret=a+ret;
            num=num/10;
       }
       if(ret/10!=0){
           return addDigits(ret);
       }
       return ret;
    }
}